package edu.udlap.spring2008.is300.finalexam.framework.mvc.observerobservable.selection;

import java.util.ArrayList;
import java.util.Iterator;

/**
 *
 * @author Ruslán Ledesma Garza
 */

///this class allows for code reuse by means of object composition...
public class SelectionChangedObservableHelper implements SelectionChangedObservable
{
    
    ArrayList<SelectionChangedListener> observers = new ArrayList<SelectionChangedListener>();
    SelectionChangedObservable observedObject;
    
    public SelectionChangedObservableHelper(SelectionChangedObservable observedObject)
    {
        this.observedObject = observedObject;
    }
    
    public void addSelectionChangedListener(SelectionChangedListener observer)
    {
        observers.add(observer);
    }

    public void removeSelectionChangedListener(SelectionChangedListener observer)
    {
        observers.remove(observer);
    }
    
    public void raiseSelectionChangedEvent(Object args)
    {
        Iterator<SelectionChangedListener> i = observers.iterator();
        SelectionChangedListener observer;
        while(i.hasNext())
        {
            observer = i.next();
            observer.selectionChanged(observedObject, args);
        }   
    }

}
